<!--舒文-->
<template>
  <div class="demo-input-suffix">
    供应商名称:
    <el-input v-model="input" placeholder="请输入供应商名称" style="width:320px"></el-input>
    <el-button type="primary" icon="el-icon-search">搜索
    </el-button>
    <el-button type="primary" icon="el-icon-circle-plus">添加
    </el-button>
    <template>
      <template>
        <div class="tableMain">
          <el-table
            :data="tableData"
            border
            style="width: 100%">
            <el-table-column prop="number" label="编号" width="120"></el-table-column>

            <!--            <el-table-column prop="date" label="日期" width="180"></el-table-column>-->
            <el-table-column prop="category" label="商品类别" width="80px"></el-table-column>
            <el-table-column prop="code" label="商品编号" width="80px"></el-table-column>
            <el-table-column prop="Trade name" label="商品名称" width="80px"></el-table-column>
            <el-table-column prop="Product model" label="商品型号" width="80px"></el-table-column>
            <el-table-column prop="Company" label="商品单位" width="80px"></el-table-column>
            <el-table-column prop="Purchase price" label="采购价格" width="80px"></el-table-column>
            <el-table-column prop="sale" label="销售价格" width="80px"></el-table-column>
            <el-table-column prop="stock" label="库存下限" width="80px"></el-table-column>
            <el-table-column prop="production" label="生产产商" width="80px"></el-table-column>
            <el-table-column prop="remarks" label="备注"></el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <!-- 点击编辑进入编辑页面进行编辑表格数据 -->
                <el-button size="mini" type="primary" class="el-icon-circle-plus-outline" @click="dialogFormVisible = true" style="float: left">修改
                </el-button>
                <el-button size="mini" type="danger" class="el-icon-delete-solid" @click="handleDelete" style="float: left">删除
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="page">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="currentPage3"
            :page-size="100"
            layout="prev, pager, next, jumper"
            :total="1000"
          ></el-pagination>
        </div>
        <!-- 下面这个用来设置点击添加按钮的弹出框，里面可以进行嵌套表格来展示弹出的表格信息,使用下面的:visible.sync来控制显示与否 -->
        <!-- 里面绑定的是我们新设置的值，填写完成后，将我们这个新值塞到页面中所有的数据当中去 -->
        <el-dialog title="供货商" :visible.sync="dialogFormVisible">
          <!-- 在el-dialog中进行嵌套el-form实现弹出表格的效果 -->
          <el-form :model="form" ref="vForm" :rules="rules" label-width="80px" size="medium"
                   @submit.native.prevent>
            <el-row>
              <el-col :span="8" class="grid-cell">
                <el-form-item label="商品类别:" prop="category" class="label-right-align">
                  <el-input v-model="form.category" type="text" clearable></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="grid-cell">
                <el-form-item label="商品编号:" prop="code" class="label-right-align">
                  <el-input v-model="form.code" type="text" clearable></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24" class="grid-cell">
                <el-form-item label="商品名称:" prop="TradeName" class="label-right-align">
                  <el-input v-model="form.TradeName" type="text" clearable></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8" class="grid-cell">
                <el-form-item label="商品型号:" prop="ProductModel" class="label-right-align">
                  <el-input v-model="form.ProductModel" type="text" clearable></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="grid-cell">
                <el-form-item label="商品单位:" prop="Company" class="label-right-align">
                  <el-input v-model="form.Company" type="text" clearable></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8" class="grid-cell">
                <el-form-item label="采购价格:" prop="PurchasePrice" class="label-right-align">
                  <el-input v-model="form.PurchasePrice" type="text" clearable></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="grid-cell">
                <el-form-item label="销售价格:" prop="sale" class="label-right-align">
                  <el-input v-model="form.sale" type="text" clearable></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8" class="grid-cell">
                <el-form-item label="库存下限:" prop="stock" class="label-right-align">
                  <el-input v-model="form.stock" type="text" clearable></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="grid-cell">
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24" class="grid-cell">
                <el-form-item label="生产厂商:" prop="production" class="label-right-align">
                  <el-input v-model="form.production" type="text" clearable></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8" class="grid-cell">
                <el-form-item label="备注:" prop="remarks" class="label-right-align">
                  <el-input type="textarea" v-model="form.remarks" rows="3"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8" class="grid-cell">



                <div slot="footer" class="dialog-footer">
                  <el-button @click="cancel">取 消</el-button>
                  <!-- 设置触发更新的方法 -->
                  <el-button type="primary" @click="update">确 定</el-button>
                </div>
              </el-col>
            </el-row>
          </el-form>
        </el-dialog>
      </template>
    </template>
  </div>
</template>

<script type="text/ecmascript-6">
export default {
  data() {
    return {
      dialogFormVisible: false,
      formLabelWidth: "120px",
      form: [],
      value6: "",
      currentPage3: 1,
      currentIndex: "",
      loading: true,
// 表格的数据
      tableData: [
        {
          category:"",
          code:"",
          TradeName:"",
          ProductModel:"",
          Company:"",
          PurchasePrice:"",
          sale:"",
          stock:"",
          production:"",
          remarks:""
        },
        {
          category:"",
          code:"",
          TradeName:"",
          ProductModel:"",
          Company:"",
          PurchasePrice:"",
          sale:"",
          stock:"",
          production:"",
          remarks:""
        },
      ],

      cityList: [
      ],

// 设置form用于进行添加的时候绑定值


    };
  },
  created() {
// 设置回调函数，进行1.5秒的loading动画显示
    setTimeout(() => {
      this.loading = false;
    }, 1500);
  },
  methods: {
    // showTime() {
    //   this.$alert(this.value6, "起止时间", {
    //     confirmButtonText: "确定",
    //     callback: action => {
    //       this.$message({
    //         type: "info",
    //         message: "已显示"
    //       });
    //     }
    //   });
    // },
// 增加数据的方式，单独的设置一些值，用于增加功能，这些值放在对象里面进行设置，然后将这个新增的对象塞到总数据里面
//     add() {
//       this.form = {
//         category:"",
//         code:"",
//         TradeName:"",
//         ProductModel:"",
//         Company:"",
//         PurchasePrice:"",
//         sale:"",
//         stock:"",
//         production:"",
//         remarks:""
//       };
// 设置点击按钮之后进行显示对话框
//       this.dialogFormVisible = true;
//     },
    update() {
// this.form.date = reformat(this.form.date);
// 可以在html上面进行设置日期的格式化
// 将我们添加的信息提交到总数据里面
      this.tableData.push(this.form);
      this.dialogFormVisible = false;
    },
    handleEdit(index, row) {
// 将数据的index传递过来用于实现数据的回显
      this.form = this.tableData[index];
      this.currentIndex = index;
// 设置对话框的可见
      this.dialogFormVisible = true;
    },
    handleDelete(index, row) {
// 设置类似于console类型的功能
      this.$confirm("永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
// 移除对应索引位置的数据，可以对row进行设置向后台请求删除数据
          this.tableData.splice(index, 1);
          this.$message({
            type: "success",
            message: "删除成功!"
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    cancel() {
// 取消的时候直接设置对话框不可见即可
      this.dialogFormVisible = false;
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    }
  }
};
</script>
<style lang="scss">
.basetable {
  .tableMain {
    margin: {
      top: 10px;
    }
  }
  .page {
    float: left;
    margin: {
      top: 10px;
    }
  }
}
</style>
